package com.example.happ.controller;

import com.example.happ.pojo.ReviewMain;
import com.example.happ.service.MerchantInfoService;
import com.example.happ.service.ReviewInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Package：com.example.happ.controller
 * @Project：happ
 * @name：王志迎
 * @Date：2024/12/26 15:37
 * @Filename：reviewInfo
 */

@RestController
@RequestMapping("/review")
public class reviewController {
    @Resource
    private ReviewInfoService reviewInfo;
    @Resource
    private MerchantInfoService merchantInfoService;
    // 添加审核记录
    @RequestMapping("/add")
    @CrossOrigin(origins = "http://localhost:8080")
    public Boolean addAuditRecord(@RequestBody Map<String, String> requestBody) {
        Boolean result = reviewInfo.addAuditRecord(requestBody);
        return result;
    }

    // 修改审核状态
    @RequestMapping("/reject")//驳回接口
    @CrossOrigin(origins = "http://localhost:8080")
    public boolean updateAuditStatus1(@RequestBody Map<String, String> requestBody) {
        System.out.println("驳回审核请求收到的数据："+requestBody);
        boolean success=false;
        success = reviewInfo.changeAuditStatus(Integer.valueOf(requestBody.get("reviewId")),Integer.valueOf(requestBody.get("status")));
        return success;
    }
    @RequestMapping("/status")//通过审核请求
    @CrossOrigin(origins = "http://localhost:8080")
    public boolean updateAuditStatus(@RequestBody Map<String, String> requestBody) {
        System.out.println("通过审核请求收到的数据："+requestBody);
        boolean success=false;
        success = merchantInfoService.updateMerchantAmountInfo1(Integer.valueOf(requestBody.get("id")),Double.valueOf(requestBody.get("amount")));
        if (!success) {
            return success;
        }
        success = reviewInfo.changeAuditStatus(Integer.valueOf(requestBody.get("reviewId")),Integer.valueOf(requestBody.get("status")));
        return success;
    }

    // 查询某个待审核记录
    @RequestMapping("/find")
    @CrossOrigin(origins = "http://localhost:8080")
    public ReviewMain getPendingRecords(@RequestBody Map<String, String> requestBody) {
        ReviewMain reviewMain = reviewInfo.getAuditRecord(requestBody);
        return reviewMain;
    }
    // 查询某个用户所有待审核记录
    @RequestMapping("/findAll")
    @CrossOrigin(origins = "http://localhost:8080")
    public Map<String, Object> getPendingRecordAll(@RequestBody Map<String, String> requestBody) {
        return reviewInfo.getAuditRecordAll(requestBody);
    }
    // 查询某个用户所有审核记录
    @RequestMapping("/selectAll")
    @CrossOrigin(origins = "http://localhost:8080")
    public Map<String, Object> selectPendingRecordAll(@RequestBody Map<String, String> requestBody) {
        System.out.println("查询某个用户所有审核记录接收的数据"+requestBody);
        return reviewInfo.selectAuditRecordAll(requestBody);
    }

}
